package com.sxds.wn.security.encrypt;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.log4j.Logger;

import com.sxds.wn.security.PasswordEncryptProvider;

/**
 * Description: <p>加密接口MD5实现</p>
 * Content Desc:<p>加密接口MD5实现<p>
 * Copy Right of Personal Tangtao 2007-2020
 * @author Andy
 * @version 1.0
 */
public class PasswordEncryptProviderMD5Impl implements PasswordEncryptProvider {
    /**
     * Logger for this class
     */
    private static final Logger logger = Logger.getLogger(PasswordEncryptProviderMD5Impl.class);

    public String encrypt(String inputString) throws SecurityException {
        byte[] result = null;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(inputString.getBytes());
            result = md.digest();
        } catch (NoSuchAlgorithmException e) {
            logger.error("没有找到MD5,请查看您的JDK版本");
            throw new SecurityException(e.getMessage());
        }
        return PasswordUtils.byteArray2HEX(result);
    }
}